
****************************

clear all
set maxvar 11000


do "Code/read_in_analysis_data.do"

***************************



* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
* PLOTTING DISTRIBUTIONS
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
	

	
	* CDF of baseline leakage -- all values
	sort log1_Tot_emiss_Leak1
	cap drop cdf_1 cdf_0
	cumul log1_Tot_emiss_Leak1 if Treatment_Ind == 1, gen(cdf_1)
	cumul log1_Tot_emiss_Leak1 if Treatment_Ind == 0, gen(cdf_0)
	twoway line cdf_1 log1_Tot_emiss_Leak1 if Treatment_Ind == 1, lpattern(dash) || ///
	       line cdf_0 log1_Tot_emiss_Leak1 if Treatment_Ind == 0, lpattern(solid) ///
		   legend(label(1 "Treatment") label(2 "Control") position(6) ring(3) row(1) region(lcolor(black))) ///
		   graphregion(color(white)) bgcolor(white) ytitle("") xtitle("log(1 + baseline leakage)")
	graph export "Paper/Figures/cdf_baseline_leakage.pdf", replace
	
	
	
	* CDF of baseline emissions -- all values
	sort log1_Emissionskgd_1
	cap drop cdf_1 cdf_0
	cumul log1_Emissionskgd_1 if Treatment_Ind==1, gen(cdf_1)
	cumul log1_Emissionskgd_1 if Treatment_Ind==0, gen(cdf_0)
	twoway line cdf_1 log1_Emissionskgd_1 if Treatment_Ind == 1, lpattern(dash) || ///
	       line cdf_0 log1_Emissionskgd_1 if Treatment_Ind == 0, lpattern(solid) ///
		   legend(label(1 "Treatment") label(2 "Control") position(6) ring(3) row(1) region(lcolor(black))) ///
		   graphregion(color(white)) bgcolor(white) ytitle("") xtitle("log(1 + baseline total emissions)")
	graph export "Paper/Figures/cdf_baseline_emissions.pdf", replace
	

	* CDF of endline leakage: conditional on zero baseline leakage
	sort log1_Tot_emiss_Leak5
	cap drop cdf_1 cdf_0
	cumul log1_Tot_emiss_Leak5 if Treatment_Ind == 1 & log1_Tot_emiss_Leak1==0, gen(cdf_1)
	cumul log1_Tot_emiss_Leak5 if Treatment_Ind == 0 & log1_Tot_emiss_Leak1==0, gen(cdf_0)
	twoway line cdf_1 log1_Tot_emiss_Leak5 if Treatment_Ind == 1 & log1_Tot_emiss_Leak1==0, lpattern(dash) || ///
	       line cdf_0 log1_Tot_emiss_Leak5 if Treatment_Ind == 0 & log1_Tot_emiss_Leak1==0, lpattern(solid) ///
		   legend(label(1 "Treatment") label(2 "Control") position(6) ring(3) row(1) region(lcolor(black))) ///
		   graphregion(color(white)) bgcolor(white) ytitle("") xtitle("log(1 + endline leakage)")
	graph export "Paper/Figures/cdf_endline_leakage_base_leak_is_zero.pdf", replace
		  
	* CDF of endline emissions: conditional on zero baseline leakage:
	sort log1_Emissionskgd_5
	cap drop cdf_1 cdf_0
	cumul log1_Emissionskgd_5 if Treatment_Ind==1 & log1_Tot_emiss_Leak1==0, gen(cdf_1)
	cumul log1_Emissionskgd_5 if Treatment_Ind==0 & log1_Tot_emiss_Leak1==0, gen(cdf_0)
	twoway line cdf_1 log1_Emissionskgd_5 if Treatment_Ind == 1 & log1_Tot_emiss_Leak1==0, lpattern(dash) || ///
	       line cdf_0 log1_Emissionskgd_5 if Treatment_Ind == 0 & log1_Tot_emiss_Leak1==0, lpattern(solid) ///
		   legend(label(1 "Treatment") label(2 "Control") position(6) ring(3) row(1) region(lcolor(black))) ///
		   graphregion(color(white)) bgcolor(white) ytitle("") xtitle("log(1 + endline total emissions)")
	graph export "Paper/Figures/cdf_endline_emissions_base_leak_is_zero.pdf", replace
	
	* CDF of endline leakage: conditional on above median baseline leakage
	sort log1_Tot_emiss_Leak5
	qui sum log1_Tot_emiss_Leak1, detail
	local leak1_median = r(p50)
	cap drop cdf_1 cdf_0
	cumul log1_Tot_emiss_Leak5 if Treatment_Ind == 1 & log1_Tot_emiss_Leak1>=`leak1_median', gen(cdf_1)
	cumul log1_Tot_emiss_Leak5 if Treatment_Ind == 0 & log1_Tot_emiss_Leak1>=`leak1_median', gen(cdf_0)
	twoway line cdf_1 log1_Tot_emiss_Leak5 if Treatment_Ind == 1 & log1_Tot_emiss_Leak1>=`leak1_median', lpattern(dash) || ///
	       line cdf_0 log1_Tot_emiss_Leak5 if Treatment_Ind == 0 & log1_Tot_emiss_Leak1>=`leak1_median', lpattern(solid) ///
		   legend(label(1 "Treatment") label(2 "Control") position(6) ring(3) row(1) region(lcolor(black))) ///
		   graphregion(color(white)) bgcolor(white) ytitle("") xtitle("log(1 + endline leakage)")
	graph export "Paper/Figures/cdf_endline_leakage_base_leak_is_above_median.pdf", replace
		  
	* CDF of endline emissions: conditional on above median baseline leakage:
	sort log1_Emissionskgd_5
	qui sum log1_Tot_emiss_Leak1, detail
	local leak1_median = r(p50)
	cap drop cdf_1 cdf_0
	cumul log1_Emissionskgd_5 if Treatment_Ind==1 & log1_Tot_emiss_Leak1>=`leak1_median', gen(cdf_1)
	cumul log1_Emissionskgd_5 if Treatment_Ind==0 & log1_Tot_emiss_Leak1>=`leak1_median', gen(cdf_0)
	twoway line cdf_1 log1_Emissionskgd_5 if Treatment_Ind == 1 & log1_Tot_emiss_Leak1>=`leak1_median', lpattern(dash) || ///
	       line cdf_0 log1_Emissionskgd_5 if Treatment_Ind == 0 & log1_Tot_emiss_Leak1>=`leak1_median', lpattern(solid) ///
		   legend(label(1 "Treatment") label(2 "Control") position(6) ring(3) row(1) region(lcolor(black))) ///
		   graphregion(color(white)) bgcolor(white) ytitle("") xtitle("log(1 + endline total emissions)")
	graph export "Paper/Figures/cdf_endline_emissions_base_leak_is_above_median.pdf", replace
	
	* CDF of endline leakage: conditional on below median but above zero leakage
	sort log1_Tot_emiss_Leak5
	qui sum log1_Tot_emiss_Leak1, detail
	local leak1_median = r(p50)
	cap drop cdf_1 cdf_0
	cumul log1_Tot_emiss_Leak5 if Treatment_Ind == 1 & log1_Tot_emiss_Leak1<`leak1_median' & log1_Tot_emiss_Leak1>0, gen(cdf_1)
	cumul log1_Tot_emiss_Leak5 if Treatment_Ind == 0 & log1_Tot_emiss_Leak1<`leak1_median' & log1_Tot_emiss_Leak1>0, gen(cdf_0)
	twoway line cdf_1 log1_Tot_emiss_Leak5 if Treatment_Ind == 1 & log1_Tot_emiss_Leak1<`leak1_median' & log1_Tot_emiss_Leak1>0, lpattern(dash) || ///
	       line cdf_0 log1_Tot_emiss_Leak5 if Treatment_Ind == 0 & log1_Tot_emiss_Leak1<`leak1_median' & log1_Tot_emiss_Leak1>0, lpattern(solid) ///
		   legend(label(1 "Treatment") label(2 "Control") position(6) ring(3) row(1) region(lcolor(black))) ///
		   graphregion(color(white)) bgcolor(white) ytitle("") xtitle("log(1 + endline leakage)")
	graph export "Paper/Figures/cdf_endline_leakage_base_leak_is_below_median_above_zero.pdf", replace
		  
	* CDF of endline emissions: conditional on below median but above zero leakage
	sort log1_Emissionskgd_5
	qui sum log1_Tot_emiss_Leak1, detail
	local leak1_median = r(p50)
	cap drop cdf_1 cdf_0
	cumul log1_Emissionskgd_5 if Treatment_Ind==1 & log1_Tot_emiss_Leak1<`leak1_median' & log1_Tot_emiss_Leak1>0, gen(cdf_1)
	cumul log1_Emissionskgd_5 if Treatment_Ind==0 & log1_Tot_emiss_Leak1<`leak1_median' & log1_Tot_emiss_Leak1>0, gen(cdf_0)
	twoway line cdf_1 log1_Emissionskgd_5 if Treatment_Ind == 1 & log1_Tot_emiss_Leak1<`leak1_median' & log1_Tot_emiss_Leak1>0, lpattern(dash) || ///
	       line cdf_0 log1_Emissionskgd_5 if Treatment_Ind == 0 & log1_Tot_emiss_Leak1<`leak1_median' & log1_Tot_emiss_Leak1>0, lpattern(solid) ///
		   legend(label(1 "Treatment") label(2 "Control") position(6) ring(3) row(1) region(lcolor(black))) ///
		   graphregion(color(white)) bgcolor(white) ytitle("") xtitle("log(1 + endline total emissions)")
	graph export "Paper/Figures/cdf_endline_emissions_base_leak_is_below_median_above_zero.pdf", replace

	
	* CDF without the transform:
	gen change_Emissionskgd = Emissionskgd_5 - Emissionskgd_1
	sort change_Emissionskgd
	cap drop cdf_1 cdf_0 
	cumul change_Emissionskgd if Treatment_Ind==1 & log1_Tot_emiss_Leak1==0, gen(cdf_1)
	cumul change_Emissionskgd if Treatment_Ind==0 & log1_Tot_emiss_Leak1==0, gen(cdf_0)
	twoway line cdf_1 change_Emissionskgd if Treatment_Ind == 1 & log1_Tot_emiss_Leak1==0, lpattern(dash) || ///
	       line cdf_0 change_Emissionskgd if Treatment_Ind == 0 & log1_Tot_emiss_Leak1==0, lpattern(solid) ///
		   legend(label(1 "Treatment") label(2 "Control") position(6) ring(3) row(1) region(lcolor(black))) ///
		   graphregion(color(white)) bgcolor(white) ytitle("") xtitle("change in total emissions")
	graph export "Paper/Figures/cdf_change_emissions_base_leak_is_zero.pdf", replace
	
	* CDF without the transform -- relative change:
	gen change_Emissionskgd_rel = (Emissionskgd_5 - Emissionskgd_1)/Emissionskgd_1
	sort change_Emissionskgd_rel
	cap drop cdf_1 cdf_0 
	cumul change_Emissionskgd_rel if Treatment_Ind==1 & log1_Tot_emiss_Leak1==0, gen(cdf_1)
	cumul change_Emissionskgd_rel if Treatment_Ind==0 & log1_Tot_emiss_Leak1==0, gen(cdf_0)
	twoway line cdf_1 change_Emissionskgd_rel if Treatment_Ind == 1 & log1_Tot_emiss_Leak1==0, lpattern(dash) || ///
	       line cdf_0 change_Emissionskgd_rel if Treatment_Ind == 0 & log1_Tot_emiss_Leak1==0, lpattern(solid) ///
		   legend(label(1 "Treatment") label(2 "Control") position(6) ring(3) row(1) region(lcolor(black))) ///
		   graphregion(color(white)) bgcolor(white) ytitle("") xtitle("relative change in total emissions")
	graph export "Paper/Figures/cdf_relative_change_emissions_base_leak_is_zero.pdf", replace
	
	
